package car.aistar.service.impl;

import car.aistar.dao.CarownerDao;
import car.aistar.entity.CarCart;
import car.aistar.entity.Carowner;
import car.aistar.service.CarownerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Carowner)表服务实现类
 *
 * @author makejava
 * @since 2020-09-30 20:21:00
 */
@Service("carownerService")
public class CarownerServiceImpl implements CarownerService {
    @Resource
    private CarownerDao carownerDao;
    /**
    *@Author 肖相荣
    *@Description //TODO 根据销售员ID进行分页展示
    *@Date 18:46 2020/10/4
    *@Param
    *@return
    **/
    @Override
    public PageInfo<Carowner> findByPage(Long id, Integer pageNow, Integer pageSize){
        PageHelper.startPage(pageNow,pageSize);
        List<Carowner> carownerList = carownerDao.findAllBySellerId(id);
        PageInfo<Carowner> petPageInfo = new PageInfo<>(carownerList);
        return petPageInfo;
    }
/**
*@Author 肖相荣
*@Description //TODO 根据销售员ID进行查找
*@Date 18:45 2020/10/4
*@Param [id]
*@return java.util.List<car.aistar.entity.Carowner>
**/

    @Override
    public List<Carowner> findAllBySellerId (Long id){
        return carownerDao.findAllBySellerId(id);
    }

    @Override
    public Carowner findAllByCarId (Long id){
        return carownerDao.findAllByCarId(id);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Carowner queryById(Long id) {
        return this.carownerDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Carowner> queryAllByLimit(int offset, int limit) {
        return this.carownerDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param carowner 实例对象
     * @return 实例对象
     */
    @Override
    public Carowner insert(Carowner carowner) {
        this.carownerDao.insert(carowner);
        return carowner;
    }

    /**
     * 修改数据
     *
     * @param carowner 实例对象
     * @return 实例对象
     */
    @Override
    public Carowner update(Carowner carowner) {
        this.carownerDao.update(carowner);
        return this.queryById(carowner.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.carownerDao.deleteById(id) > 0;
    }

    @Override
    public List<Carowner> queryAll(Carowner carowner) {
        return this.carownerDao.queryAll(carowner);
    }
}